package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/exercicio01")
public class Exercicio01 extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		gerarTabuada(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		gerarTabuada(req, resp);
	}
	
	private void gerarTabuada(HttpServletRequest req, HttpServletResponse resp) throws IOException{
		String sNumero = req.getParameter("numero");
		int numero = Integer.parseInt(sNumero);
		PrintWriter out  = resp.getWriter();
		resp.setContentType("text/html");
		out.println("<html><head><title>Exercicio 01</title></head>");
		out.println("<body>");
		out.println("<table border=\"1\">");
		out.println("<th id=\"multiplicador\">Número </th>");
		out.println("<th id=\"simbolo\"> * </th>");
		out.println("<th id=\"multiplicando\"> Número</th>");
		out.println("<th id=\"resultado\">Resultado </th>");
		for(int i =1; i < 11; i++){
			out.println("<tr>");
			out.println("<td hearders=\"multiplicador\"><center>" +sNumero+"</center></td>");
			out.println("<td hearders=\"simbolo\"> * </td>");
			out.println("<td hearders=\"multiplicando\"><center>" +i+"</center></td>");
			out.println("<td hearders=\"resultdo\"><center>" +i * numero+"</center></td>");
			out.println("</tr>");
		}
		out.println("</table>");
		
		out.println("</body>");
		out.println("</html>");
	}
}
